package br.com.jhd.aba.utils.interceptadores;

import java.io.IOException;

import org.vraptor.Interceptor;
import org.vraptor.LogicException;
import org.vraptor.LogicFlow;
import org.vraptor.annotations.In;
import org.vraptor.scope.ScopeType;
import org.vraptor.view.ViewException;

import br.com.jhd.aba.dominio.entidades.Usuario;

public class AutorizadorInterceptor implements Interceptor {

	@In(scope=ScopeType.SESSION, required=true)
	private Usuario usuarioLogado;

	public void intercept(LogicFlow flow) throws LogicException, ViewException {
		if (this.usuarioLogado == null) {
			try {
				flow.getLogicRequest().getResponse().sendRedirect("Expirou.jsp");
			} catch (IOException e) {
				throw new LogicException(e);
			}
		} else {
			flow.execute();
		}
	}
}


